<template>
  <div>
    <div class="btn">
      <a-button type="primary" @click="addAssociations">
        添加关联
      </a-button>
    </div>
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <span slot="actions" slot-scope="text, record">
          <a @click="handlEdit(record)">{{ record.tiMing }}</a>
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="cancel(record)">取消关联</a>
        </span>
      </a-table>
    </div>
  </div>
</template>

<script>
import pick from 'lodash.pick'
import { JeecgListMinxinPost } from '@/mixins/JeecgListMinxinPost'

import {  correlationEdit } from '@/api/api'

import '@/assets/less/TableExpand.less'
import JDate from '@/components/jeecg/JDate'

export default {
  name: 'relation',
  mixins: [JeecgListMinxinPost],
  inject: ['reload'],
  components: {
    JDate
  },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '题号',
          dataIndex: 'actions',
          align: 'center',
          // fixed:"right",
          width: 147,
          scopedSlots: { customRender: 'actions' }
        },
        {
          title: '文件编号',
          align: 'center',
          dataIndex: 'wenJianBianHao'
        },
        {
          title: '密级',
          align: 'center',
          dataIndex: 'miJi'
        },
        {
          title: '保管期限',
          align: 'center',
          dataIndex: 'baoCunQiXian'
        },
        {
          title: '年度',
          align: 'center',
          dataIndex: 'nianDu'
        },
        {
          title: '归档机构',
          align: 'center',
          dataIndex: 'guiDangJiGou'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          // fixed:"right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
     
      url: {
        list: '/wsWenShuDangAnController/gl/queryCorrelationList',
        delete: '/wsWenShuDangAnController/delete',
        deleteBatch: '/wsZhuWenShu/deleteBatch',
      }
    }
  },
  created: function() {},
  methods: {
    // 添加关联
    addAssociations() {
      if (this.$route.query.id) {
        
        this.$router.push({ path: '/associations', query: { id: this.$route.query.id } })
        
      } else {
        this.$router.push('/associations')
      }
    },
    // 取消关联
    cancel(val){
      sessionStorage.setItem("keyIndex", "3");
      correlationEdit({
        guanLianBiaoShi: 0,
        guanLianZhuWenShuId: 0,
        id:val.id,
        zhuWenShuId: this.$route.query.id
      }).then(res => {
        if (res.success) {
        sessionStorage.setItem("keyIndex", "3");
          this.reload()
        }
      })
    },
  }
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
.btn {
  width: 100%;
  text-align: right;
  margin: 10px 0;
  .ant-btn {
    margin-right: 30px;
  }
}
</style>
